package com.wc.AlgoOJ_train.train1.c6.A613;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/1/10 23:01
 * @description 剪花布条
 * kmp算法
 * http://43.138.190.70:8888/p/A613
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.next();
            if (s.equals("#")) {
                return;
            }
            String sub = sc.next();
            System.out.println(kmp(s, sub, 0));
        }
    }

    static int[] nextVal;
    static int[] next;

    static int kmp(String str, String sub, int pos) {
        int lenStr = str.length();
        int lenSub = sub.length();
        next = new int[lenSub + 1];
        nextVal = new int[lenSub + 1];
        int i = pos;
        int j = 0;
        int ans = 0;
        getNextVal(sub);
        while (i < lenStr) {
            if (j == -1 || str.charAt(i) == sub.charAt(j)) {
                i++;
                j++;
            } else {
                j = nextVal[j];
            }
            if (j == lenSub) {
                j = 0;
                ans++;
            }
        }
        return ans;
    }

    static void getNextVal(String sub) {
        char[] chs = sub.toCharArray();
        next[0] = -1;
        next[1] = 0;
        int i = 2;
        int lenSub = sub.length();
        while (i <= lenSub) {
            int k = next[i - 1];
            while (k != -1 && chs[k] != chs[i - 1]) {
                k = next[k];
            }
            next[i] = k + 1;
            i++;
        }
        nextVal[0] = next[0];
        for (int j = 1; j < lenSub; j++) {
            if (chs[next[j]] == chs[j]) {
                nextVal[j] = nextVal[next[j]];
            } else {
                nextVal[j] = next[j];
            }
        }
    }
}
